
$(function(){
    $('#pageGrid').datagrid({
        url:'page',
        pagination:true,
        columns:[[
            {field:'id',title:'ID',width:45},
            {field:'realname',title:'姓名',width:65,align:'center'},
            {field:'sex',title:'性别',width:40},
            {field:'certType',title:'证件类型',width:80,align:'center'},
            {field:'cert',title:'证件号码',width:160,align:'center'},
            {field:'userType',title:'用户类型',width:80},
          
            { field: 'opt', title: '操作', width: 80,
            	formatter:function(value,row,index){  
                    var d = '<a href="#" mce_href="#" onclick="del(\''+ row.id +'\')">删除</a> ';  
                    return d;
            	}
            }
        ]]
    });
})
function del(id){  //删除操作  
     $.messager.confirm('确认','确认删除?',function(row){  
           if(row){  
                 var selectedRow = $('#pageGrid').datagrid('getSelected');  //获取选中行  
                 $.ajax({  
                	 type:"get",
                	 url:'del?id='+id,    
                	 success:function(){                	
                		 alert('删除成功')
                 }
           });  
           $('#pageGrid').datagrid('deleteRow',row.id); 
           $('#pageGrid').datagrid('reload');
           
       }  
   });  
}  

var url;
function newUser(){
    $('#dlg').dialog('open').dialog('center').dialog('setTitle','New User');
    $('#fm').form('clear');
    url = 'addUser';
}
function saveUser(){
    $('#fm').form('submit',{
        url: url,
        onSubmit: function(){
            return $(this).form('validate');
        },
        success: function(result){
            var result = eval('('+result+')');
            if (result.errorMsg){
                $.messager.show({
                    title: 'Error',
                    msg: result.errorMsg
                });
            } else {
                $('#dlg').dialog('close');        // close the dialog
                $('#dg').datagrid('reload');    // reload the user data
            }
        }
    });
}

